﻿@using HPIT.RentHouse.DTO
@model RolesEditDTO
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout1.cshtml";
    var perList = ViewBag.perList as List<PerissionDTO>;
}

<form action="@Url.Action("EditRole","Roles")" method="post" class="form form-horizontal" id="form-admin-add">
    @Html.HiddenFor(a => a.Id);
    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" value="@Model.Name" placeholder="" id="Name" name="Name">
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3">角色权限：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <dl class="permission-list">
                <dt><label>选择权限</label></dt>
                <dd>
                    <dl class="cl permission-list2">
                        @foreach (PerissionDTO permissions in perList)
                        {
                            <dt>
                                <label class="">
                                    <input type="checkbox" name="PermissionIds" value="@permissions.Id" />
                                    @permissions.Description
                                </label>
                            </dt>
                        }
                    </dl>
                </dd>
            </dl>
        </div>
    </div>
    <div class="row cl">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
            <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
        </div>
    </div>
</form>
@section footScript{
    <script type="text/javascript">
        $(function () {
            $("#form-admin-add").validate({
                rules: {
                    Name: {
                        required: true,
                        maxlength: 6
                    },
                },
                submitHandler: function (form) {
                    //使用ajax方式提交表单
                    $(form).ajaxSubmit({
                        success: function (data) {
                            console.log(data)
                            if (data.State == 1) {
                                parent.location.reload();
                            } else {
                                layer.msg(data.ErrorMessage, { icon: 2 });
                            }
                        }
                    })
                }
            })
        })
    </script>
}

